<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="4">
            <a-tooltip placement="topLeft" overlayClassName="custom-tooltip">
              <template slot="title">
                <p style="margin-bottom: 0">查询技巧：</p>
                <p style="margin-bottom: 0">1.多选查询：多个查询字段之间用逗号","分隔。</p>
                <span>例如：</span>
                <span style="margin-bottom: 0;color: greenyellow">CP.000002，SC.000002</span>
              </template>
              <a-form-item label="物料代码">
                <a-input placeholder="请输入物料代码" v-model="queryParam.materialCode"></a-input>
              </a-form-item>
            </a-tooltip>
          </a-col>
          <a-col :md="6" :sm="4">
            <a-tooltip arrow-point-at-center>
              <template slot="title">
                <p style="margin-bottom: 0">查询技巧：</p>
                <p style="margin-bottom: 0">
                  1.多选查询：多个查询字段之间用逗号","分隔。例如：
                  <span style="color: greenyellow">散热器，喷涂件</span>
                </p>
                <p style="margin-bottom: 0">
                  2.模糊查询：一个查询字段之间用管道符号"|"分隔。例如：
                  <span style="color: greenyellow">散热器|喷涂件</span>
                </p>
              </template>
              <a-form-item label="物料名称">
                <a-input placeholder="请输入物料名称" v-model="queryParam.materialName"></a-input>
              </a-form-item>
            </a-tooltip>
          </a-col>
          <a-col :md="6" :sm="4">
            <a-form-item label="物料类型">
              <j-multi-select-tag v-model="queryParam.materialType" dictCode="hf_material_type,material_type_name,id" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="4">
            <a-form-item label="物料仓库">
              <j-multi-select-tag v-model="queryParam.warehouse" dictCode="hf_warehouse,warehouse_name,id" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button icon="search" type="primary" @click="searchQuery">查询</a-button>
      <a-button icon="reload" type="primary" @click="searchReset">重置</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('物料库存')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <hf-material-storage-modal ref="modalForm" @ok="modalFormOk"></hf-material-storage-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import HfMaterialStorageModal from './modules/HfMaterialStorageModal'

export default {
  name: 'HfMaterialStorageList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    HfMaterialStorageModal
  },
  data() {
    return {
      description: '物料库存管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '物料代码',
          align: 'center',
          dataIndex: 'materialCode'
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName'
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'sap'
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unit_dictText'
        },
        {
          title: '物料类型',
          align: 'center',
          dataIndex: 'materialType_dictText'
        },
        // {
        //   title:'单箱数',
        //   align:"center",
        //   dataIndex: 'perNumber'
        // },
        // {
        //   title:'箱数',
        //   align:"center",
        //   dataIndex: 'number'
        // },
        // {
        //   title:'数量',
        //   align:"center",
        //   dataIndex: 'totalNumber'
        // },
        {
          title: '收料仓库',
          align: 'center',
          dataIndex: 'warehouse_dictText'
        },
        {
          title: '库存',
          align: 'center',
          dataIndex: 'storage'
        },
        // {
        //   title:'待检库存',
        //   align:"center",
        //   dataIndex: 'underDetectStorage'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/warehouse/hfMaterialStorage/list',
        delete: '/warehouse/hfMaterialStorage/delete',
        deleteBatch: '/warehouse/hfMaterialStorage/deleteBatch',
        exportXlsUrl: '/warehouse/hfMaterialStorage/exportXls',
        importExcelUrl: 'warehouse/hfMaterialStorage/importExcel'
      },
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'materialId', text: '物料ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialCode', text: '物料代码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialName', text: '物料名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sap', text: '规格型号', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'unit',
        text: '单位',
        dictCode: 'hf_material_unit,material_unit_name,id'
      })
      fieldList.push({
        type: 'string',
        value: 'materialType',
        text: '物料类型',
        dictCode: 'hf_material_type,material_type_name,id'
      })
      fieldList.push({ type: 'int', value: 'perNumber', text: '单箱数', dictCode: '' })
      fieldList.push({ type: 'double', value: 'number', text: '箱数', dictCode: '' })
      fieldList.push({ type: 'double', value: 'totalNumber', text: '数量', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'warehouse',
        text: '收料仓库',
        dictCode: 'hf_warehouse,warehouse_name,id'
      })
      fieldList.push({ type: 'double', value: 'storage', text: '库存', dictCode: '' })
      fieldList.push({ type: 'double', value: 'underDetectStorage', text: '待检库存', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
